<template>
	<div>
		<el-card class="box-card">
			<el-table :data="SignAllocationList" border>
				<el-table-column prop="date" label="日期" />
				<el-table-column prop="allocationNum" label="分配数量" />
				<el-table-column label="操作" width="80px">
					<template slot-scope="scope">
						<div class="button">
							<el-button type="primary" size="mini" @click="UpdateClick(scope.row)">修改</el-button>
						</div>
					</template>
				</el-table-column>
			</el-table>
			<el-dialog :title="title" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
				<el-form label-position="left" label-width="80px" :model="ObjectList">
					<el-form-item label="日期">
						<el-input placeholder="请输入日期" disabled v-model="ObjectList.date"></el-input>
					</el-form-item>
					<el-form-item label="数量">
						<el-input placeholder="请输入数量" v-model="ObjectList.allocationNum"></el-input>
					</el-form-item>
				</el-form>
				<span slot="footer" class="dialog-footer">
					<el-button @click="dialogVisible = false">取 消</el-button>
					<el-button type="primary" @click="ClickUser()">确 定</el-button>
				</span>
			</el-dialog>
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :page-sizes="[10, 15]"
				:page-size="fy.size" layout="total, sizes, prev, pager, next, jumper" :total="total">
			</el-pagination>
		</el-card>
	</div>
</template>

<script>
	import * as sySignAllocationApi from "@/api/Add";
	import * as SignAllocationApi from "@/api/Search";
	export default {
		data() {
			return {
				SignAllocationList: [],
				title: "",
				dialogVisible: false,
				ObjectList: {},
				total: 0,
				fy: {
					size: 10,
					current: 1,
				},
			};
		},
		methods: {
			UpdateClick(row) {
				sySignAllocationApi.SignAllocationID({
					id: row.id
				}).then((res) => {
					this.ObjectList = res.data;
					this.dialogVisible = true;
				});
				this.title = "修改签到配置";
			},
			ClickUser() {
				sySignAllocationApi.SignAllocation(this.ObjectList).then((res) => {
					if (res.data == true) {
						this.dialogVisible = false;
						this.SearchData();
						this.$notify({
							title: "成功",
							message: "修改成功",
							type: "success",
						});
					} else {
						this.dialogVisible = false;
						this.SearchData();
						this.$notify({
							title: "失败",
							message: "修改失败",
							type: "error",
						});
					}
				});
			},
			SearchData() {
				SignAllocationApi.InsertsignAllocation(this.fy).then((res) => {
					this.total = res.data.total;
					this.SignAllocationList = res.data.records;
				});
			},
			handleSizeChange(value) {
				this.fy.size = value;
				this.SearchData();
			},
			handleCurrentChange(value) {
				this.fy.current = value;
				this.SearchData();
			},
			handleClose(done) {
				this.$confirm("确认关闭？")
					.then((_) => {
						done();
					})
					.catch((_) => {});
			},
		},
		created() {
			this.SearchData();
		},
	};
</script>

<style lang="scss" scoped>
	.box-card {
		width: 95%;
		margin: auto;
	}
</style>
